home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / cpu / m6502 / ill02.h < prev    next >
Text File  |  2000-05-08  |  10KB  |  263 lines

  1. /*****************************************************************************
  2.  *
  3.  *     ill02.h
  4.  *     Addressing mode and opcode macros for the NMOS 6502 illegal opcodes
  5.  *
  6.  *     Copyright (c) 1998,1999,2000 Juergen Buchmueller, all rights reserved.
  7.  *     65sc02 core Copyright (c) 2000 Peter Trauner, all rights reserved.
  8.  *
  9.  *     - This source code is released as freeware for non-commercial purposes.
  10.  *     - You are free to use and redistribute this code in modified or
  11.  *       unmodified form, provided you list me in the credits.
  12.  *     - If you modify this source code, you must add a notice to each modified
  13.  *       source file that it has been changed.  If you're a nice person, you
  14.  *       will clearly mark each change too.  :)
  15.  *     - If you wish to use this for commercial purposes, please contact me at
  16.  *       pullmoll@t-online.de
  17.  *     - The author of this copywritten work reserves the right to change the
  18.  *       terms of its usage and license at any time, including retroactively
  19.  *     - This entire notice must remain in the source code.
  20.  *
  21.  *****************************************************************************/
  22.  
  23. /* test with the excellent C64 Emulator test suite
  24.    ? at www.funet.fi/pub/cbm/documents/chipdata/tsuit215.zip
  25.    good reference in the vice emulator (source) distribution doc/64doc.txt
  26.  
  27.    $ab=OAL like in 6502-NMOS.extra.opcodes, vice so in vice (lxa)
  28. */
  29.  
  30. /***************************************************************
  31.  ***************************************************************
  32.  *            Macros to emulate the 6510 opcodes
  33.  ***************************************************************
  34.  ***************************************************************/
  35.  
  36. /* 6510 ********************************************************
  37.  *    ANC logical and, set carry from bit of A
  38.  ***************************************************************/
  39. #define ANC                                                     \
  40.     P &= ~F_C;                                                    \
  41.     A = (UINT8)(A & tmp);                                        \
  42.     if (A & 0x80)                                                \
  43.         P |= F_C;                                                \
  44.     SET_NZ(A)
  45.  
  46. /* 6510 ********************************************************
  47.  *    ASR logical and, logical shift right
  48.  ***************************************************************/
  49. #define ASR                                                     \
  50.     tmp &= A;                                     \
  51.     LSR
  52.  
  53. /* 6510 ********************************************************
  54.  * AST    and stack; transfer to accumulator and index X
  55.  * logical and stack (LSB) with data, transfer result to S
  56.  * transfer result to accumulator and index X also
  57.  ***************************************************************/
  58. #define AST                                                     \
  59.     S &= tmp;                                                    \
  60.     A = X = S;                                                    \
  61.     SET_NZ(A)
  62.  
  63. /* 6510 ********************************************************
  64.  *    ARR logical and, rotate right
  65.  ***************************************************************/
  66. #define ARR                                                     \
  67.     if( P & F_D )                                                \
  68.     {                                                            \
  69.         int lo, hi, t;                                            \
  70.         tmp &= A;                                                \
  71.         t = tmp;                                                \
  72.         hi = tmp &0xf0;                                         \
  73.         lo = tmp &0x0f;                                         \
  74.         if( P & F_C )                                            \
  75.         {                                                        \
  76.             tmp = (tmp >> 1) | 0x80;                            \
  77.             P |= F_N;                                            \
  78.         }                                                        \
  79.         else                                                    \
  80.         {                                                        \
  81.             tmp >>= 1;                                            \
  82.             P &= ~F_N;                                            \
  83.         }                                                        \
  84.         if( tmp )                                                \
  85.             P &= ~F_Z;                                            \
  86.         else                                                    \
  87.             P |= F_Z;                                           \
  88.         if( (t^tmp) & 0x40 )                                    \
  89.             P|=F_V;                                             \
  90.         else                                                    \
  91.             P &= ~F_V;                                            \
  92.         if( lo + (lo & 0x01) > 0x05 )                            \
  93.             tmp = (tmp & 0xf0) | ((tmp+6) & 0xf);                \
  94.         if( hi + (hi & 0x10) > 0x50 )                            \
  95.         {                                                        \
  96.             P |= F_C;                                            \
  97.             tmp = (tmp+0x60) & 0xff;                            \
  98.         }                                                        \
  99.         else                                                    \
  100.             P &= ~F_C;                                            \
  101.     }                                                            \
  102.     else                                                        \
  103.     {                                                            \
  104.         tmp &= A;                                                \
  105.         ROR;                                                    \
  106.         P &=~(F_V|F_C);                                         \
  107.         if( tmp & 0x40 )                                        \
  108.             P|=F_C;                                             \
  109.         if( (tmp & 0x60) == 0x20 || (tmp & 0x60) == 0x40 )        \
  110.             P|=F_V;                                             \
  111.     }
  112.  
  113. /* 6510 ********************************************************
  114.  *    ASX logical and X w/ A, subtract data from X
  115.  ***************************************************************/
  116. #define ASX                                                     \
  117.     P &= ~F_C;                                                    \
  118.     X &= A;                                                     \
  119.     if (X >= tmp)                                                \
  120.         P |= F_C;                                                \
  121.     X = (UINT8)(X - tmp);                                        \
  122.     SET_NZ(X)
  123.  
  124. /* 6510 ********************************************************
  125.  *    AXA transfer index X to accumulator, logical and
  126.  * depends on the data of the dma device (videochip) fetched
  127.  * between opcode read and operand read
  128.  ***************************************************************/
  129. #define AXA                                                     \
  130.     A = (UINT8)( (A|0xee)& X & tmp);                            \
  131.     SET_NZ(A)
  132.  
  133. /* 6510 ********************************************************
  134.  *    DCP decrement data and compare
  135.  ***************************************************************/
  136. #define DCP                                                     \
  137.     tmp = (UINT8)--tmp;                                         \
  138.     P &= ~F_C;                                                    \
  139.     if (A >= tmp)                                                \
  140.         P |= F_C;                                                \
  141.     SET_NZ((UINT8)(A - tmp))
  142.  
  143. /* 6502 ********************************************************
  144.  *    DOP double no operation
  145.  ***************************************************************/
  146. #define DOP                                                     \
  147.     PCW++
  148.  
  149. /* 6510 ********************************************************
  150.  *    ISB increment and subtract with carry
  151.  ***************************************************************/
  152. #define ISB                                                     \
  153.     tmp = (UINT8)++tmp;                                         \
  154.     SBC
  155.  
  156. /* 6510 ********************************************************
  157.  *    LAX load accumulator and index X
  158.  ***************************************************************/
  159. #define LAX                                                     \
  160.     A = X = (UINT8)tmp;                                         \
  161.     SET_NZ(A)
  162.  
  163. /* 6510 ********************************************************
  164.  *    OAL load accumulator and index X
  165.  ***************************************************************/
  166. #define OAL                                                     \
  167.     A = X = (UINT8)((A|0xee)&tmp);                                \
  168.     SET_NZ(A)
  169.  
  170. /* 6510 ********************************************************
  171.  * RLA    rotate left and logical and accumulator
  172.  *    new C <- [7][6][5][4][3][2][1][0] <- C
  173.  ***************************************************************/
  174. #define RLA                                                     \
  175.     tmp = (tmp << 1) | (P & F_C);                                \
  176.     P = (P & ~F_C) | ((tmp >> 8) & F_C);                        \
  177.     tmp = (UINT8)tmp;                                            \
  178.     A &= tmp;                                                    \
  179.     SET_NZ(A)
  180.  
  181. /* 6510 ********************************************************
  182.  * RRA    rotate right and add with carry
  183.  *    C -> [7][6][5][4][3][2][1][0] -> C
  184.  ***************************************************************/
  185. #define RRA                                                     \
  186.     tmp |= (P & F_C) << 8;                                        \
  187.     P = (P & ~F_C) | (tmp & F_C);                                \
  188.     tmp = (UINT8)(tmp >> 1);                                    \
  189.     ADC
  190.  
  191. /* 6510 ********************************************************
  192.  * SAX    logical and accumulator with index X and store
  193.  ***************************************************************/
  194. #define SAX                                                     \
  195.     tmp = A & X
  196.  
  197. /* 6510 ********************************************************
  198.  *    SLO shift left and logical or
  199.  ***************************************************************/
  200. #define SLO                                                     \
  201.     P = (P & ~F_C) | ((tmp >> 7) & F_C);                        \
  202.     tmp = (UINT8)(tmp << 1);                                    \
  203.     A |= tmp;                                                    \
  204.     SET_NZ(A)
  205.  
  206. /* 6510 ********************************************************
  207.  *    SRE logical shift right and logical exclusive or
  208.  *    0 -> [7][6][5][4][3][2][1][0] -> C
  209.  ***************************************************************/
  210. #define SRE                                                     \
  211.     P = (P & ~F_C) | (tmp & F_C);                                \
  212.     tmp = (UINT8)tmp >> 1;                                        \
  213.     A ^= tmp;                                                    \
  214.     SET_NZ(A)
  215.  
  216. /* 6510 ********************************************************
  217.  * SAH    store accumulator and index X and high + 1
  218.  * result = accumulator and index X and memory [PC+1] + 1
  219.  ***************************************************************/
  220. #define SAH tmp = A & X & (EAH+1)
  221.  
  222. /* 6510 ********************************************************
  223.  * SSH    store stack high
  224.  * logical and accumulator with index X, transfer result to S
  225.  * logical and result with memory [PC+1] + 1
  226.  ***************************************************************/
  227. #define SSH                                                     \
  228.     S = A & X;                                                    \
  229.     tmp = S & (EAH+1)
  230. #if 0
  231.     tmp = S = A & X;                                            \
  232.     tmp &= (UINT8)(cpu_readop_arg((PCW + 1) & 0xffff) + 1)
  233. #endif
  234.  
  235. /* 6510 ********************************************************
  236.  * SXH    store index X high
  237.  * logical and index X with memory[PC+1] and store the result
  238.  ***************************************************************/
  239. #define SXH tmp = X & (EAH+1)
  240.  
  241. /* 6510 ********************************************************
  242.  * SYH    store index Y and (high + 1)
  243.  * logical and index Y with memory[PC+1] + 1 and store the result
  244.  ***************************************************************/
  245. #define SYH tmp = Y & (EAH+1)
  246.  
  247. /* 6510 ********************************************************
  248.  *    TOP triple no operation
  249.  ***************************************************************/
  250. #define TOP                                                     \
  251.     PCW+=2
  252.  
  253. /* 6510 ********************************************************
  254.  *    KIL Illegal opcode
  255.  * processor halted: no hardware interrupt will help,
  256.  * only reset
  257.  ***************************************************************/
  258. #define KIL                                                     \
  259.     PCW--;                                                        \
  260.     logerror("M6510 KILL opcode %04x: %02x\n",                  \
  261.                 PCW, cpu_readop(PCW))
  262.  
  263.